﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;

namespace BLL
{
  public class OrderDetailsBLL
  {
    public List<OrderDetail> GetAll()
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        return data.OrderDetails.ToList();
      }
    }
    public List<OrderDetail> GetByOrderId(int orderId)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        return data.OrderDetails.Where(p => p.IdOrder == orderId).ToList();
      }
    }
    public List<OrderDetail> GetByProductId(string productId)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        return data.OrderDetails.Where(p => p.IdProduct == productId).ToList();
      }
    }

    public void Add(OrderDetail obj)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        data.OrderDetails.InsertOnSubmit(obj);
        data.SubmitChanges();
      }
    }
    public void Add(List<OrderDetail> obj)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        data.OrderDetails.InsertAllOnSubmit(obj);
        data.SubmitChanges();
      }
    }
    public void DeleteByOrderId(int orderId)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        List<OrderDetail> list = data.OrderDetails.Where(p => p.IdOrder == orderId).ToList();
        data.OrderDetails.DeleteAllOnSubmit(list);
        data.SubmitChanges();
      }
    }
    public void DeleteByProductId(string productId)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        List<OrderDetail> list = data.OrderDetails.Where(p => p.IdProduct == productId).ToList();
        data.OrderDetails.DeleteAllOnSubmit(list);
        data.SubmitChanges();
      }
    }
  }
}
